﻿/*
 * 设计模式 - 责任链模式
 * 目的: 层层传递,层层处理
 */

var context = new ProcessContext();
var manager = new ProcessA();
var leader = new ProcessB();
var director = new ProcessC();

leader.Next = director;
director.Next = manager;

leader.Process(context);


class ProcessContext
{
    public string Name { get; set; }
}


/// <summary>
/// 必须是抽象类
/// </summary>
abstract class ProcessHandler
{
    public ProcessHandler? Next { get; set; }

    public abstract void Process(ProcessContext context);
}

class ProcessA : ProcessHandler
{
    public override void Process(ProcessContext context)
    {
        context.Name = "领导";

        Console.WriteLine($"流程 A,{context.Name}处理");
        Next?.Process(context);
    }
}

class ProcessB : ProcessHandler
{
    public override void Process(ProcessContext context)
    {
        context.Name = "主管";
        Console.WriteLine($"流程 B,{context.Name}处理");
        Next?.Process(context);
    }
}

class ProcessC : ProcessHandler
{
    public override void Process(ProcessContext context)
    {
        context.Name = "总监";
        Console.WriteLine($"流程 C,{context.Name}处理");
        Next?.Process(context);
    }
}
